package leetcode.for_offer.s06;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: DRevelation
 * @Date: 2021/9/10 14:15
 */
public class ReversePrint {

    List<Integer> tmp = new ArrayList<>();

    int[] reversePrint(ListNode head) {
        recur(head);
        int[] res = new int[tmp.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = tmp.get(i);
        }
        return res;
    }

    void recur(ListNode head) {
        if (head == null) {
            return;
        }
        recur(head.next);
        tmp.add(head.getVal());
    }

    public static void main(String[] args) {
        ListNode l1 = new ListNode(2, null);
        ListNode l2 = new ListNode(3, l1);
        ListNode l3 = new ListNode(1, l2);

        ReversePrint rp = new ReversePrint();
        int[] print = rp.reversePrint(l3);
        System.out.println("print = " + Arrays.toString(print));
    }

}

@Data
@AllArgsConstructor
class ListNode {
    int val;
    ListNode next;
}